﻿namespace Methods
{
    using System;

    public class Student
    {
        private readonly DateTime minBirthDateYear = new DateTime(1880, 01, 01).Date;
        private DateTime birthDate;

        public Student()
        {
            this.About = string.Empty;
        }
        
        public string FirstName { get; set; }

        public string LastName { get; set; }

        public DateTime BirthDate
        {
            get
            {
                return this.birthDate.Date;
            }

            set
            {
                if (value == null)
                {
                    throw new NullReferenceException("The BirthDate cannot be null!");
                }
                else if (value.Date < this.minBirthDateYear.Date || value.Date >= DateTime.Today.Date)
                {
                    throw new ArgumentOutOfRangeException("The BirthDate must be greater than 1900 and less Tomorrow!");
                }

                this.birthDate = value;
            }
        }

        public string LivingCity { get; set; }

        public string About { get; set; }

        public string OtherInfo
        {
            get
            {
                string about = string.Empty;
                if (this.About != string.Empty)
                {
                    about = string.Format("{0}, ", this.About);
                }

                return string.Format("From {0}, {1}born at {2}", this.LivingCity, about, this.BirthDate.Date.ToShortDateString());
            }
        }

        public bool IsOlderThan(Student otherStudent)
        {
            return this.BirthDate > otherStudent.BirthDate;
        }
    }
}